00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _fall_back_matrix_methods_hpp_
00022 #define _fall_back_matrix_methods_hpp_
00023
00024 #include "gridpack/parallel/communicator.hpp"
00025 #include "matrix_interface.hpp"
00026 #include "complex_operators.hpp"
00027
00028 namespace gridpack {
00029 namespace math {
00030 namespace fallback {
00031
00032
00033
00034
00035
00036
00037
00038 template <typename T, typename I>
00039 void
00040 addDiagonal(BaseMatrixInterface<T, I>& A, const T& x)
00041 {
00042 I lo, hi;
00043 A.localRowRange(lo, hi);
00044 for (I i = lo; i < hi; ++i) {
00045 A.addElement(i, i, x);
00046 }
00047 A.ready();
00048 }
00049
00050
00051
00052 template <typename T, typename I>
00053 double
00054 norm2(const parallel::Communicator& comm, const BaseMatrixInterface<T, I>& A)
00055 {
00056 I ncols(A.cols());
00057 I lo, hi;
00058 A.localRowRange(lo, hi);
00059 struct l2_norm<T> accum;
00060
00061 T v;
00062 for (I i = lo; i < hi; ++i) {
00063 for (I j = 0; j < ncols; ++j) {
00064 A.getElement(i, j, v);
00065 accum(v);
00066 }
00067 }
00068 double lresult(accum.result());
00069 double result;
00070 boost::mpi::all_reduce(comm, lresult, result, std::plus<double>());
00071 result = sqrt(result);
00072 return result;
00073 }
00074
00075 }
00076 }
00077 }
00078
00079
00080 #endif